#include <REGX52.H>
#include "Delay.h"	
#include "Nixie.h"
#include "TIMER.h"

unsigned int s = 99;
unsigned int k = 0;


void Timer0()
{
	TMOD = 0x01;
	TH0 = (65536 - 9174) / 256;
	TL0 = (65536 - 9174) % 256;
	TR0 = 0;
}

void TimerInt()
{
	EA = 1;

	EX0 = 1;
	IT0 = 1;

	EX1 = 1;
	IT1 = 1;
}
void timeInt2() interrupt 2
{
	TR0 = ~TR0;
}


void timeInt1() interrupt 0
{
	unsigned int a = 0;
	unsigned int b = 0;
	unsigned int c = 0;

	P2 = ~0x01;
	Timer0();
	TR0 = 1;

	while (c < 4)
	{
		for (a = 0; a < 8; a++)
		{
			while (b <10)
			{
				while (TF0 == 0);
				TH0 = (65536 - 9174) / 256;
				TL0 = (65536 - 9174) % 256;
				b++;
				TF0 = 0;
			}
			b = 0;
		
			P2 = ~(0x01 << a);
		}
		c++;
	}
	c = 0;
	
}


void main()
{
	Timer0 ();
	TimerInt();

	Nixie(1, s / 10);
	Nixie(2, s % 10);

		if (P3_1 == 0)
		{
			Delay(20);
			while (P3_1 == 0);
			Delay(20);
			TR0 = 1;
			
			while (1)
			{
				while (k < 50)
				{
					Nixie(1, s / 10);
					Nixie(2, s % 10);
					while (TF0 == 0)
					{
						Nixie(1, s / 10);
						Nixie(2, s % 10);
					}
					TH0 = (65536 - 9174) / 256;
					TL0 = (65536 - 9174) % 256;
					k++;
					TF0 = 0;
				}
				k = 0;
				s--;

				if (s == 0)
				{
					while (1)
					{
						Nixie(1, s / 10);
						Nixie(2, s % 10);
					}
				}

			}
			


		}

}